//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================



using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography.X509Certificates;
using System.Configuration;
using System.Globalization;
using System.ServiceModel;
using System.IdentityModel.Tokens;
using System.ServiceModel.Configuration;

namespace Shp.Security.BrokeredReceiver
{
    static class ServiceConfiguration
    {
        /// <summary>
        /// Gets the name of the STS store.
        /// </summary>
        /// <value>The name of the issuer store.</value>
        static public StoreName StsStoreName
        {
            get { return StoreName.My; }
        }

        /// <summary>
        /// Gets the STS store location.
        /// </summary>
        /// <value>The issuer store location.</value>
        static public StoreLocation StsStoreLocation
        {
            get { return StoreLocation.LocalMachine; }
        }


        // Statics initialized from app.config
        static public string StsDistinguishedName
        {
            get { return OperationContext.Current.Host.Credentials.ServiceCertificate.Certificate.SubjectName.Name; }
        }

        /// <summary>
        /// Gets the name of the issuer store.
        /// </summary>
        /// <value>The name of the issuer store.</value>
        static public StoreName IssuerStoreName
        {
            get { return StoreName.TrustedPeople; }
        }

        /// <summary>
        /// Gets the issuer store location.
        /// </summary>
        /// <value>The issuer store location.</value>
        static public StoreLocation IssuerStoreLocation
        {
            get { return StoreLocation.LocalMachine; }
        }

        /// <summary>
        /// Gets the name of the issuer distinguished.
        /// </summary>
        /// <value>The name of the issuer distinguished.</value>
        static public string IssuerDistinguishedName
        {
            get
            {
                if(OperationContext.Current.Host.Credentials.IssuedTokenAuthentication.KnownCertificates.Count == 0)
                {
                    return null;
                }
                return OperationContext.Current.Host.Credentials.IssuedTokenAuthentication.KnownCertificates[0].SubjectName.Name; 
            }
        }

        /// <summary>
        /// Gets the scoped certificates used for encrypting the SAML token.
        /// </summary>
        /// <value>The scoped certificates.</value>
        static public X509ScopedServiceCertificateElementCollection ScopedCertificates
        {
            get { return StsConfiguration.Current.ScopedCertificates; }
        }

        // Issuer name placed into issued tokens
        static public string SecurityTokenServiceName
        {
            get { return OperationContext.Current.Host.Description.Name; }
        } 
     }
}
